package com.xingzhe.pengji.security.dao.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.xingzhe.pengji.framework.dao.BaseIBatisDaoImpl;
import com.xingzhe.pengji.security.dao.UserIbatisDao;
import com.xingzhe.pengji.security.domain.User;
import com.xingzhe.pengji.security.mapper.UserMapper;

/**
 * @Title ： 三江学院 毕业设计
 * @Description ：
 * @author ：LuFengLiang
 * @Company: IT行者工作室
 * @Copyright: Copyright (c) 2012-2-24
 * @version ： 1.0
 * @param <T>
 */
@Repository
public class UserIbatisDaoImpl<T extends User> extends BaseIBatisDaoImpl<T> implements UserIbatisDao<T>
{
    @Autowired
    private UserMapper<T> userMapper;

    private Logger logger = LoggerFactory.getLogger(UserIbatisDaoImpl.class);

    @Override
    public boolean addUser(T entity) 
    {
        try
        {
            userMapper.saveUser(entity);
        }
        catch (Exception e)
        {
            logger.error(e.toString());
            return false;
        }
        return true;
    }
 
    @Override
    public boolean updateUser(T entity) 
    {
        try
        {
            userMapper.updateUser(entity);
        }
        catch (Exception e)
        {
            logger.error(e.toString());
            return false;
        }
        return true;
    }

    public List<T> getUsers(Map<String, Object> map){
        return userMapper.getUsers(map);
    }
    @Override
    public List<T> getPageList(Map<String, Object> map)
    {
        return userMapper.queryForPaginatedList(map);
    }

    @Override
    public int getItemCount(Map<String, Object> map) throws DataAccessException
    {
        return userMapper.getItemCount(map);
    }

	@Override
	public List<String> getAllAuthoritiesByUserName(String userName) {
		return userMapper.getAllAuthoritiesByUserAccount(userName);
	}
}
